<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function foo(){
        var i = 0;
        return function () {
            i++;
            console.log(i);
        }
    }
    var r = foo();
    r();
    r();
    var r2 = foo();
    r();
    r();
</script>
</body>
</html>